{extend name="platform/base" /}
{block name="resources"/}
<style type="text/css">
.required{
	color:red;margin-right:10px;
}
.error{
	font-size: 12px;
    line-height: 16px;
    color: red;
    margin-top: 10px;
	display:none;
}
</style>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 添加文章分类</header>
	<div class="panel-body">
		<form class="form-horizontal" id="form" name="form" onsubmit="">
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="required">*</span>分类名称</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="name" value="">
				</div>
				<p class="error">请输入分类名称</p>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">上级分类</label>
				<div class="col-sm-4">
					<select id="pid" name="account" class="form-control m-b">
						<option value="0">顶级分类</option> 
						 {volist name="article_class_frist_list" id="vo"}
							<option value="{$vo.class_id}" >{$vo.name}</option>
					    {/volist}
					    
					</select>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">排序</label>
				<div class="col-md-1">
					<input type="text" class="form-control" id="sort" value="">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="addArticleClassAjax()" class="btn btn-primary">保存</a>
				</div>
			</div>
		</form>
	</div>
</section>
<script type="text/javascript">
/**
 * 添加分类
 */
function addArticleClassAjax(){
		var name = $("#name").val();
		var pid = $("#pid").val();
		var sort = $("#sort").val();
	if(verify(name)){
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/Cms/addUpdateAritcleClass')}",
			data : {
				'name' : name,
				'pid' : pid,
				'sort' : sort,
			},
			async : true,
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', "添加成功","{:__URL('PLATFORM_MAIN/Cms/articleClassList')}");
				}else{
					showMessage('error', "添加失败");
				}	
			}
		});
	}	
}

function verify(name){
	if(name == ''){
		$("#name").parent().next(".error").show();
  		 $("#name").focus();
  		 return false;
	}
	return true;
}
</script>
{/block} 

